package com.test.basic;

public class StringPoolDemo {
    public static void main(String[] args) {
        String str = new StringBuilder("kai").append("hui").toString();
        System.out.println(str);//58tongcheng
        System.out.println(str.intern());//58tongcheng
        System.out.println(str == str.intern());//true


        String str2 = new StringBuilder("ja").append("va").toString();
        System.out.println(str2);//java
        System.out.println(str2.intern());//java
        System.out.println(str2 == str2.intern());//false

        String s1 =  new String("abc");
        String s2 =  new String("abc");
        String s3 = "abc";
        System.out.println(s1 == s2);//false
        System.out.println(s1 == s3);//false

        s1 = s1.intern();
        System.out.println(s1 == s2.intern());//true
        System.out.println(s1== s3); //true


    }
}
